CFLAGS = -Wall -std=c99 -lm -fpic -coverage -ftest-coverage -fprofile-arcs

rngs.o: rngs.h rngs.c
	gcc -c rngs.c -g  $(CFLAGS)

dominion.o: dominion.h dominion.c rngs.o
	gcc -c dominion.c -g  $(CFLAGS)

playdom: dominion.o playdom.c
	gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)

testDrawCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

badTestDrawCard: badTestDrawCard.c dominion.o rngs.o
	gcc -o badTestDrawCard -g  badTestDrawCard.c dominion.o rngs.o $(CFLAGS)

testBuyCard: testBuyCard.c dominion.o rngs.o
	gcc -o testBuyCard -g  testBuyCard.c dominion.o rngs.o $(CFLAGS)

testAll: dominion.o testSuite.c
	gcc -o testSuite testSuite.c -g  dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
	gcc -c interface.c -g  $(CFLAGS)

player: player.c interface.o
	gcc -o player player.c -g  dominion.o rngs.o interface.o $(CFLAGS)

all: playdom player testDrawCard testBuyCard badTestDrawCard unittestresults.out

clean:
	rm -f *.o playdom.exe playdom test.exe test player player.exe testDrawCard testDrawCard.exe testBuyCard testBuyCard.exe badTestDrawCard badTestDrawCard.exe *.gcov *.gcda *.gcno *.so
	rm -f unittests cardtests unittestresults.out
	rm -f randomtestcard randomtestadventurer randomtestcard.out randomtestadventurer.out
	rm -f testdominion testdominion.out gameResults.out

unittests: unittests.h unittests.c unittest1.c unittest2.c unittest3.c unittest4.c dominion.o rngs.o
	gcc -o unittests -g $^ $(CFLAGS)

cardtests: cardtests.h cardtests.c cardtest1.c cardtest2.c cardtest3.c cardtest4.c dominion.o rngs.o
	gcc -o cardtests -g $^ $(CFLAGS)

unittestresults.out: unittests cardtests
	./unittests >>  unittestresults.out
	./cardtests >>  unittestresults.out
	gcov -b dominion.c >>  unittestresults.out

flip: clean
	rsync -avz . flip:/tmp/zibolskc_build
	ssh flip -t 'cd /tmp/zibolskc_build && make clean && make all'

randomtestcard: randomtestcard.c dominion.o rngs.o interface.o
	gcc -o $@ -g $^ $(CFLAGS)

randomtestadventurer: randomtestadventurer.c dominion.o rngs.o interface.o
	gcc -o $@ -g $^ $(CFLAGS)

randomtestcard.out: randomtestcard
	rm -f dominion.c.gcov
	./randomtestcard
	gcov -b dominion.c > $@
	sed -n "/1192:    case sea_hag:/,/return 0/p" dominion.c.gcov >> $@

randomtestadventurer.out: randomtestadventurer
	rm -f dominion.c.gcov
	./randomtestadventurer
	gcov -b dominion.c > $@
	sed -n "/int adventurer_effect/,/return 0/p" dominion.c.gcov >> $@

testdominion: testdominion.c dominion.o rngs.o interface.o
	gcc -o $@ -g $^ $(CFLAGS)

testdominion.out: testdominion
	rm -f dominion.c.gcov gameResults.out
	echo "Cleared gameResults.out"
	./testdominion 1 1000
	echo "Ran with 1000 iterations, and a starting seed of 1" > $@
	gcov -b dominion.c >> $@
